package com.sqllite.springbootsqlitejdbc.repository;

import com.sqllite.springbootsqlitejdbc.bean.CreditRealTimeParse;
import com.sqllite.springbootsqlitejdbc.frame.ReflectionMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CreditRealTimeParseDao {
    private final JdbcTemplate jdbcTemplate;

    public CreditRealTimeParseDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void insert(CreditRealTimeParse record) {
        String sql = "INSERT INTO credit_real_time_parse_table (pa01ai01, write_date, pinfo_mobile_last_6m_cnt) VALUES (?, ?, ?)";
        jdbcTemplate.update(sql, record.getPa01ai01(), record.getWriteDate(), record.getPinfoMobileLast6mCnt());
    }

    public void delete(String pa01ai01) {
        String sql = "DELETE FROM credit_real_time_parse_table WHERE pa01ai01 = ?";
        jdbcTemplate.update(sql, pa01ai01);
    }

    public void update(CreditRealTimeParse record) {
        String sql = "UPDATE credit_real_time_parse_table SET write_date = ?, pinfo_mobile_last_6m_cnt = ? WHERE pa01ai01 = ?";
        jdbcTemplate.update(sql, record.getWriteDate(), record.getPinfoMobileLast6mCnt(), record.getPa01ai01());
    }

    public CreditRealTimeParse findById(String pa01ai01) {
        String sql = "SELECT * FROM credit_real_time_parse_table WHERE pa01ai01 = ?";
        return jdbcTemplate.queryForObject(sql, new Object[]{pa01ai01}, (rs, rowNum) -> {
            CreditRealTimeParse record = new CreditRealTimeParse();
            record.setPa01ai01(rs.getString("pa01ai01"));
            record.setWriteDate(rs.getString("write_date"));
            record.setPinfoMobileLast6mCnt(rs.getInt("pinfo_mobile_last_6m_cnt"));
            // 其他字段...
            return record;
        });
    }

    public List<CreditRealTimeParse> findAll() {
        String sql = "SELECT * FROM credit_real_time_parse_table";
        return jdbcTemplate.query(sql, (rs, rowNum) -> ReflectionMapper.mapRow(rs, CreditRealTimeParse.class));
    }

    public void callCreditRealTime(String reportId) {


    }
    private String sql = "SELECT * FROM credit_real_time_parse_table";
}

